'use strict';
var express = require('express');
var app = express();
var dataOne = require('./dataOne');  // 引入数据
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
const route = express.Router();
route.use((req,res,next)=>{
    // console.log('这里是拦截器');
    next();
})
route.post('/test',(req,res)=>{
    res.send('this is the home router');
})


//设置跨域访问
app.all('*', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By",' 3.2.1');
    res.header("Content-Type", "application/json;charset=utf-8");
    next();
});

// 以下是数据接口
// 首页图片
app.get('/456',function(req,res){
//写个接口123
    res.status(200),
    res.json(dataOne.questionsT)
});


app.get('/123',function(req,res){
//写个接口123
    res.status(200),
    res.json(dataOne.questions)
});





// 以下是配置
app.use('/static',express.static("./static"));
//配置服务端口
var server = app.listen(3000, function () {
    var host = server.address().address;
    var port = server.address().port;
    console.log('直接访问 http://127.0.0.1:3000/123');
})
